package com.hnas.ecard.dao.impl;

import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.StringUtil;
import com.hnas.ecard.dao.MerchantDao;
import com.hnas.ecard.orm.Merchant;

@Component("merchantDao")
public class MerchantDaoImpl extends BaseDaoImpl<Merchant> implements MerchantDao{
	
	private static Log log = LogFactory.getLog(MerchantDaoImpl.class);

	public MerchantDaoImpl() {
		super(Merchant.class);
	}

	@Override
	public void deleteById(String id) {
		String sql = "delete from tbl_merchant_info where id=?1";
		Query query = this.getEntityManager().createNativeQuery(sql);
		query.setParameter(1, id);
		query.executeUpdate();
	}

	@Override
	public void update(Merchant vo) {
		String sql = "update tbl_merchant_info set ";
		if(StringUtil.isNotEmpty(vo.getName())){
			sql+="name='"+vo.getName()+"',";
		}
		if(StringUtil.isNotEmpty(vo.getPic())){
			sql+="pic='"+vo.getPic()+"',";
		}
		if(sql.endsWith(",")){
			sql = sql.substring(0,sql.lastIndexOf(","));
		}
		sql+=" where id="+vo.getId();
		
		Query query = this.getEntityManager().createNativeQuery(sql);
		query.executeUpdate();
		
	}

}
